package kechengsheji;
//定义事件处理方法
class PressBAdd implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
        d1 = Double.parseDouble(tf.getText());
        op = 0;
        tf.setText("");
      } catch(Exception ee){}
    }
  }

  class PressBSub implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
        d1 = Double.parseDouble(tf.getText());
        op = 1;
        tf.setText("");
      } catch(Exception ee) {}
    }
  }

  
  class PressBMul implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	d1 = Double.parseDouble(tf.getText());
        op = 2;
        tf.setText("");
      } catch(Exception ee) {}
    }
  }

  class PressBDiv implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	d1 = Double.parseDouble(tf.getText());
        op = 3;
        tf.setText("");
      } catch(Exception ee) {}
    }
  }

  class PressBYx implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	d1 = Double.parseDouble(tf.getText());
        op = 4;
        tf.setText("");
      } catch(Exception ee) {}
    }
  }
  
  class PressBEqual implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	double result = 0;
        d2 = Double.parseDouble(tf.getText());
        switch(op) {
      	  case 0:
      	    result = d1 + d2;
      	    break;
          case 1:
            result = d1 - d2;
            break;
          case 2:
            result = d1 * d2;
            break;
          case 3:
            result = d1 / d2;
            break;
          case 4:
            result = Math.pow(d1,d2);
            break;
          default:
        }
        tf.setText(String.valueOf(result));
      } catch(Exception ee) {}
    }
  }
  
  class PressBSqrt implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	double x = Double.parseDouble(tf.getText());
        double y;
        y = Math.sqrt(x);
        tf.setText(y+"");
      } catch(Exception ee) {}
    }
  }

  class PressBInt implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	double x = Double.parseDouble(tf.getText());
        double y;
        y = Math.floor(x);
        tf.setText(y+"");
      } catch(Exception ee) {}
    }
  }
  
  class PressBCos implements  ActionListener {
	    public void actionPerformed(ActionEvent e) {
	      try {
	      	double x = Double.parseDouble(tf.getText());
	        double y;
	        y = Math.cos(x);
	        tf.setText(y+"");
	      } catch(Exception ee) {}
	    }
	  }
  
  class PressBSin implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
      	double x = Double.parseDouble(tf.getText());
        double y;
        y = Math.sin(x);
        tf.setText(y+"");
      } catch(Exception ee) {}
    }
  }
    
  

  class PressBBack implements  ActionListener {
    public void actionPerformed(ActionEvent e) {
      try {
       double c= Double.parseDouble(tf.getText());
        tf.setText(""+1/c);
      } catch(Exception ee) {}
    }
  }